﻿Imports System.Data.SqlClient
Public Class members_merchantsuccesscaseslist
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private ps As New PreparedStatement(sSQL)
    Private i As Integer
    Private pages As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("uid") <> Nothing And Session("uid") <> "") Then
            Dim memberId, strErr As String
            Dim companyId As String = ""
            Dim sum, sumdesc As Integer
            i = Request("page")
            If i = Nothing Or i = 0 Then
                i = 1
            End If
            memberId = Session("uid")
            strErr = ""
            ps.strSql = "select * from merchant where owner_id =@ownerId"
            ps.addParameter("ownerId", memberId)
            Dim conn As SqlConnection = objfind.getConn()

            objrd = objfind.dr(ps, strErr, conn, objrd)
            If (objrd.Read()) Then
                companyId = objrd.Item("company_id")
            End If
            ps.strSql = "select count(*) from company_successcase where company_id=@companyId and lang_flag='zh'"
            ps.parameters.Clear()
            ps.addParameter("companyId", companyId)
            objrd = objfind.dr(ps, strErr, conn, objrd)
            objrd.Read()
            sum = objrd.Item(0)
            pages = (sum \ 10) + 1
            If i >= pages Then
                i = pages
            ElseIf i <= 0 Then
                i = 1
            End If
            If (i = pages) Then
                sumdesc = sum
            Else
                sumdesc = i * 10
            End If
            totalPage.InnerText = i.ToString & "/" & pages.ToString()
            ps.strSql = "select top(" & i & "*10) * from company_successcase where company_id=@companyId and lang_flag='zh'" & _
                    "and id not in (" & _
                    "select top (" & i - 1 & "*10) id from company_successcase where company_id=@companyId and lang_flag='zh' " & _
                    "order by title" & _
                    ") and id not in (select top(" & sum - sumdesc & ") id from company_successcase where company_id=@companyId and lang_flag='zh'" & _
                    "order by title desc) order by title"
            'ps.strSql = "select * from company_successcase where company_id=@companyId and lang_flag='zh'"
            ps.parameters.Clear()
            ps.addParameter("companyId", companyId)
            objrd = objfind.dr(ps, strErr, conn, objrd)
            purchaseList.InnerHtml = "<table width=""98%"" border=""0"" cellpadding=""0"" cellspacing=""1"" style=""margin-top:10px;"">" & _
                                         "<tr>" & _
                                             "<td width=""50%"" bgcolor=""#CCCCCC"">标题</td>" & _
                                             "<td width=""20%"" bgcolor=""#CCCCCC"">创建时间</td>" & _
                                             "<td width=""30"" bgcolor=""#CCCCCC"">操作</td>" & _
                                         "</tr>"
            While (objrd.Read())
                purchaseList.InnerHtml += "<tr>" & _
                                            "<td bgcolor=""#F5F5F5""> " & objrd("title") & "</td>" & _
                                            "<td bgcolor=""#F5F5F5""> " & objrd("create_date") & "</td>" & _
                                            "<td bgcolor=""#F5F5F5""> <a href=""members-merchantsuccesscases.aspx?editType=delete&successId=" & objrd("id") & """ >删除</a>&nbsp&nbsp&nbsp&nbsp<a href=""members-merchantsuccesscases.aspx?successId=" & objrd("id") & """>修改</a>" & _
                                        "</tr>"
            End While
            objfind.closeConn(conn)

            purchaseList.InnerHtml += "</table>"
            pageNav.InnerHtml = "<a href=""members-merchantsuccesscaseslist.aspx?page=1"">首页</a>" & _
                                "<a href=""members-merchantsuccesscaseslist.aspx?page=" & i - 1 & """>上一页</a>" & _
                                "<a href=""members-merchantsuccesscaseslist.aspx?page=" & i + 1 & """>下一页</a>" & _
                                "<a href=""members-merchantsuccesscaseslist.aspx?page=" & pages & """>尾页</a>"
        Else
            Response.Redirect("../cn_login.aspx")
        End If
    End Sub

    Protected Sub submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles submit.Click
        Response.Redirect("members-merchantsuccesscaseslist.aspx?page=" & page1.Text & "")
    End Sub

End Class